<?php
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */
class ome_ctl_admin_ldward extends desktop_controller{
    
    var $workground = 'ome_ctl_admin_ldward';
    var $pagelimit = 10;
    var $axsupplier_model ;
    public function __construct($app)
    {
        parent::__construct($app);
        $this->member_model = $this->app->model('axsupplier');
        header("cache-control: no-store, no-cache, must-revalidate");
    }
   function index(){
   	
        $custom_actions[] = array('label'=>app::get('ome')->_('添加'),'href'=>'index.php?app=ome&ctl=admin_ldward&act=add_page','target'=>'dialog::{title:\''.app::get('ome')->_('添加').'\',width:560,height:300}');

        $actions_base['title'] = app::get('ome')->_('Ldward档案');
        $actions_base['actions'] = $custom_actions;
        $actions_base['allow_detail_popup'] = true;
        $actions_base['use_buildin_set_tag'] = false;
        $actions_base['use_buildin_export'] = false;
        $actions_base['use_buildin_filter'] = false;

        $actions_base['use_view_tab'] = false;

        $this->finder('ome_mdl_ldward',$actions_base);
    }


    function add_page()
    {

        $sql = "SELECT shop_id,shop_bn,name from sdb_ome_shop where leemantype='1' ";
        $shop_datas = kernel::database()->select($sql);
        $this->pagedata['shopdata'] = $shop_datas;
        $this->pagedata['pam_account']['operator']=kernel::single('desktop_user')->get_name();
        $this->display('admin/ldward/new.html');
    }

    function add()
    {

                // 修改
        $this->begin();
        $ldward_model = $this->app->model('ldward');//当前app下使用
        //$ldward_model = app::get('ome')->model('ldward');//跨app使用


        $begin= strtotime($_POST['pam_account']['begin_date']);
        $end=strtotime($_POST['pam_account']['end_date']);
        if($begin>$end)
        {
            $this->end(false, "开始时间大于结束时间");
        }
        $arr_order['pam_account']['shop_id'] = $_POST['pam_account']['shop_id'];
        $arr_order['pam_account']['code'] = $_POST['pam_account']['code'];
        $arr_order['pam_account']['name'] = $_POST['pam_account']['name'];
        $arr_order['pam_account']['begin_date'] =  $begin;
        $arr_order['pam_account']['end_date'] = $end;
        $arr_order['pam_account']['operator'] = $_POST['pam_account']['operator'];
        $arr_order['pam_account']['create_time'] = time();
        
        if($_POST)
        {
            if($_POST['pam_account']['id'] != '')
            {

                $db = kernel::database();
                $db->beginTransaction();
                unset($arr_order['pam_account']['create_time']);
                if( $ldward_model->update($arr_order['pam_account'], array('id' => $_POST['pam_account']['id'])) )
                {
                    $db->commit();
                }else{
                    $msg = '保存失败，请联系客服!';
                    return false;
                }
                $this->end(true, app::get('ome')->_('编辑成功！'));
            } 
            else 
            {
                $db = kernel::database();
                $db->beginTransaction();
                if( $ldward_model->save($arr_order['pam_account']) )
                {
                    $db->commit();
                }else{
                    $msg = '保存失败，请联系客服!';
                    return false;
                }
                $this->end(true, app::get('ome')->_('添加成功！'));
            }
        }
    }
    function lmedit()
    {
        if(isset($_GET['id'])){
            $id = $_GET['id'];
            $ome_mdl_ldward_obj = kernel::single('ome_mdl_ldward');
            $ldward = $ome_mdl_ldward_obj->getList('*', array('id'=>$id), 0, 1);

        }


        $sql = "SELECT shop_id,shop_bn,name from sdb_ome_shop where leemantype='1' ";
        $shop_datas = kernel::database()->select($sql);
        $this->pagedata['shopdata'] = $shop_datas;
        $this->pagedata['pam_account'] = $ldward[0];
        $this->page('admin/ldward/new.html');

    }

    //理文测试
    
}
